package main

import (
	"gitee.com/shijun123456/rpcVotes/test/hystrix/middlewares"
	"github.com/afex/hystrix-go/hystrix"
	"github.com/gin-gonic/gin"
	"net"
	"net/http"
)

func main() {
	hystrixStreamHandler := hystrix.NewStreamHandler()
	hystrixStreamHandler.Start()

	go http.ListenAndServe(net.JoinHostPort("", "81"), hystrixStreamHandler)
	// 81 用来进行检测获取到的 hy熔断信息
	r := gin.Default()
	r.GET("/api/ping/baidu", func(c *gin.Context) {
		_, err := http.Get("https://www.baidu.com")
		if err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
			return
		}
		c.JSON(http.StatusOK, gin.H{"msg": "success"})
	}, middlewares.CircuitBreakerWrapper)
	r.Run()
}
